package com.csdj.t309springboot.kaoshi.service;
import com.csdj.t309springboot.kaoshi.entity.User;
import com.csdj.t309springboot.kaoshi.entity.UserExample;
import com.csdj.t309springboot.kaoshi.mapper.UserMapper;
import com.csdj.t309springboot.kaoshi.utils.SecurityUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserService{

    @Resource
    UserMapper mapper;



    public User login(String account, String password){
        UserExample userExample = new UserExample();
        userExample.createCriteria().andUserCodeEqualTo(account)
                .andUserPasswordEqualTo(SecurityUtils.md5Hex(password));
        List<User> list = mapper.selectByExample(userExample);
        System.out.println("size:"+list.size());
        if(list != null && list.size()>0 ){
            System.out.println("==登录成功==");
            return list.get(0);
        }
        System.out.println("< 登录失败 >");
        return null;
    }


    public List<User> getAllUsers() {

        return mapper.selectByExample(new UserExample());
    }
}
